﻿using FangDuShi_Admin.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FangDuShi_Admin.Controllers
{

      [OutputCache(Duration = 0, VaryByParam = "none")]
    public class UserController : AdminBaseController
    {
          BLL.Login loginBll = new BLL.Login();
      
          //
        // GET: /User/
        public ActionResult Index()
        {
            GetUserTreeData();
            return View();
        }

          public ActionResult UserChooseTree()
        {

            GetUserTreeData();
            return PartialView();
        }

          private void GetUserTreeData()
          {
              List<Model.PrvUser> listUsers = loginBll.GetPrvUserListAll();
              string treeJsonStr = "";
              if (listUsers.Count > 0)
              {

                  treeJsonStr += "[";
                  int i = 0;

                  foreach (Model.PrvUser mdl in listUsers)
                  {

                      if (i == 0)
                      {
                          treeJsonStr += "{'title':'" + mdl.FUserName + "','key':'" + mdl.FLogID + "','expand':true,'isFolder':false,'activate':true";
                          i++;
                      }
                      else
                      {
                          treeJsonStr += "{'title':'" + mdl.FUserName + "','key':'" + mdl.FLogID + "','expand':true,'isFolder':false";

                      }

                      treeJsonStr += ",'icon':'" + Url.Content("~/img/user_male.png") + "'";

                      treeJsonStr += ",'href':'" + Url.Action("UserInfo", "User", new { FLogID = mdl.FLogID }) + "','target':'contentframe'";
                      treeJsonStr += "},";
                  }
                  treeJsonStr = treeJsonStr.Substring(0, treeJsonStr.LastIndexOf(","));
                  treeJsonStr += "]";
                  treeJsonStr = treeJsonStr.Replace("'", "\"");
              }
              ViewData["treeJsonStr"] = treeJsonStr;
          }

          public ActionResult UserInfo(string FLogID)
          {
              Model.PrvUser mdl = loginBll.GetModel(FLogID);
              return View(mdl);
          }
	}
}